import { UserInfoAPI } from "@/request/api"
export default {
    namespaced: true,
    state: {
        cartTotal: 40,
        userInfo: {
            nikName: "",
            coin: 1000,
            headImg: require('../../assets/img/userImg.f8bbec5e.png')
        }
    },
    mutations: {
        changeUserInfo(state, payload) {
            state.userInfo.nikName = payload.userInfo.nickName;
            state.userInfo.coin = payload.userInfo.coin;
            state.userInfo.headImg = payload.userInfo.headImg;
            state.cartTotal = payload.cartTotal;
        },
        initUserInfo(state) {
            state.cartTotal = 0,
                state.userInfo = {
                    nikName: "",
                    coin: 1000,
                    headImg: require('../../assets/img/userImg.f8bbec5e.png')
                }
        }
    },
    actions: {
        async asyncChangeUserInfo({ commit }, payload) {
            let res = await UserInfoAPI()
            commit('changeUserInfo', res.data.data)
        }
    }
}